# -*- coding: utf-8 -*-

__author__	= 'Souheil CHELFOUH <souheil@chelfouh.com>'
__docformat__	= 'plaintext'

from AccessControl import ClassSecurityInfo
from Products.Archetypes.public import registerType
from Products.PloneGossip.config import PROJECTNAME
from Products.PloneGossip.content import PGContainer
from Products.PloneGossip.schemas import bodySchema


class PGPost( PGContainer ):
    """ A forum post """

    # Configuration of my type
    portal_type = metal_type    = "PGPost"
    archetype_name              = "post"
    content_icon                = "post_icon.gif"
    schema                      = PGContainer.schema.copy() + \
                                  bodySchema
    typeDescription             = "A simple plone gossip post"
    typeDescMsgId               = "plonegossip_post"
    global_allow                = False

    # Contents
    allowed_content_types       = ('PGPost',)
    
    # Views
    default_view                = 'post_view'
    immediate_view              = 'post_view'
    suppl_views                 = ()

    schema['description'].schemata = 'metadata'

    # Security
    security = ClassSecurityInfo()
    
    security.declareProtected('View', 'post_view')
    def post_view(self):
        """
        """
        request  = self.REQUEST
        
        response = request.RESPONSE
        parent = self.getMyParent()
        if self.isReviewable():
            response.redirect(parent.absolute_url() + '/#' + self.UID())
        else:
            response.redirect(parent.absolute_url())


registerType(PGPost, PROJECTNAME)
